package com.ihome.android.market2.view;

import android.content.Context;
import android.text.Html;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ihome.android.academy.R;

public class PageLine extends LinearLayout {
	private final String TAG = PageLine.class.getSimpleName();
    private TextView txtPage;
       
	public PageLine(Context context) {
		super(context);
		initial();
	}

	public PageLine(Context context, AttributeSet attrs) {
		super(context, attrs);
		initial();
	}
	
	
	public void setPageNum(int curPage, int count, int numPPage ,boolean fee) {
		int pageNum = count/numPPage;
		if (pageNum* numPPage != count) {
			pageNum++;
		}
		if (pageNum == 0) {
			pageNum = 1;
		}
		
		if (curPage >= pageNum) {
			curPage = pageNum;
		}
		
		if(fee){
			txtPage.setText(Html.fromHtml(getResources().getString(R.string.pagenum1, curPage, pageNum, count)));
		}else{
			txtPage.setText(Html.fromHtml(getResources().getString(R.string.pagenum, curPage, pageNum, count)));
		}		
				
	}
	
	void initial() {	
		txtPage = new TextView(this.getContext());
		txtPage.setTextColor(getResources().getColor(R.color.white));
		txtPage.setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimensionPixelSize(R.dimen.textSizeMiddle));
		
		this.addView(txtPage);
	}

	
}

